<?php

	require_once 'FileUploadController.php';
	require_once 'ForumController.php';
	require_once 'LoginController.php';
	require_once 'RegisterController.php';
	require_once './view/NavigationView.php';
	require_once './view/PageView.php';
	
	class MasterController {
		
		public function DoControll(Database $db) {
			
			$html = "";
			$fileC = new FileUploadController();
			$forumC = new ForumController();
			$forumHandler = new ForumHandler($db);
			$loginHandler = new LoginHandler($db);
			$navView = new NavigationView();
			$pageView = new PageView();			
						
			//Om Log In-länken är klickad.
			if ($navView->ShowLogin() == true) {
				$loginC = new LoginController();
				$html = $loginC->DoControll($loginHandler);
			}
			
			//Om Register-länken är klickad.
			if ($navView->ShowRegister() == true) {
				$regHandler = new RegisterHandler($db);
				$registerC = new RegisterController();
				$html = $registerC->DoControll($regHandler);
			}	
				
			$fileList = $fileC->DoControll($loginHandler); 
			$forum = $forumC->DoControll($loginHandler, $forumHandler);
			$links = $navView->Links();
		
			//Returnerar sidan.
			return $pageView->Merge($fileList, $forum, $links, $html);		
		}
	}
